package com.wzcl.app.dao.model;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.wzcl.app.dao.model.common.Base;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Getter
@Setter
@Entity
@Table(name = "commodity",
    indexes = {
        @Index(columnList = "resourceId"),
        @Index(columnList = "type")
    }
)
@ApiModel(value = "商品表")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Commodity implements Base, Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ApiModelProperty(value = "货物ID号,Course或Material表中的Id")
    private Integer resourceId;

    @ApiModelProperty(value = "类型")
    private Integer type;

    @ApiModelProperty(value = "商品名称")
    private String name;

    @ApiModelProperty(value = "图片")
    private String pictures;

    @ApiModelProperty(value = "原价")
    private BigDecimal oldPrice;

    @ApiModelProperty(value = "现价")
    private BigDecimal currentPrice;

    @ApiModelProperty(value = "库存")
    private Integer stock;

    @ApiModelProperty(value = "销量")
    private Integer sold;

    @ApiModelProperty(value = "是否上架")
    private Boolean sale;

    @ApiModelProperty(value = "上架时间")
    private Date saleTime;

    @ApiModelProperty(value = "是否需要配送")
    private Boolean needDelivery;

    @ApiModelProperty(value = "活动类型")
    private String activityTypes;

    @ApiModelProperty(value = "是否推荐")
    private Boolean recommend;

    @ApiModelProperty(value = "开启规格配置")
    private Boolean spec;

    @ApiModelProperty(value = "状态")
    private Integer state;

    @CreatedDate
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @LastModifiedDate
    @ApiModelProperty(value = "创建时间")
    private Date updateTime;

    @ApiModelProperty(value = "排序字段")
    private Integer orderNo;

    @JsonIgnoreProperties(value = {"commodityList"})
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "commodityAndActivity",
            joinColumns = {@JoinColumn(name = "commodityId",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "activityId",referencedColumnName = "id")})
    @OrderBy("orderNo desc")
    private List<Activity> activityList;
}
